/**
 * Person model
 */
package data.converter.model;

import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import org.json.simple.JSONStreamAware;
import org.json.simple.JSONValue;

public class Person implements JSONStreamAware{

	private String personCode;
	private String firstName;
	private String lastName;
	private List<String> emails;
	
	private Address address;
	
	public String getPersonCode() {
		return personCode;
	}

	public void setPersonCode(String personCode) {
		this.personCode = personCode;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public List<String> getEmails() {
		return emails;
	}
	
	public void addEmail(String email) {
		if (emails == null) {
			emails = new ArrayList<String>();
		}
		emails.add(email);
	}
	
	public void setEmails(List<String> emails) {
		this.emails = emails;
	}
	
	public Address getAddress() {
		return address;
	}
	
	public void setAddress(Address address) {
		this.address = address;
	}
	
	public void writeJSONString(Writer out){
		LinkedHashMap obj = new LinkedHashMap();
		obj.put("personCode", personCode);
		obj.put("firstName", firstName);
		obj.put("lastName", lastName);
		obj.put("address", address);
		obj.put("emails", emails);
		try {
			JSONValue.writeJSONString(obj, out);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
